﻿using Sidvall.CodeGenerator.Security;
using System.Collections.Generic;
using System.Linq;

namespace Sidvall.CodeGenerator
{
    public class DomainModel
    {
        #region Public Members

        public string DomainName { get; set; }
        public string RootFrameworkNamespace { get; set; }
        public string BusinessRemoteLayerAssemblyName { get; set; }
        public string BusinessLayerNamespace { get; set; }
        public string BusinessLayerFrameworkNamespace { get; set; }
        public string ResourceLayerNamespace { get; set; }
        public string ResourceLayerFrameworkNamespace { get; set; }
        public string DataLayerAssemblyName { get; set; }
        public string DataLayerNamespace { get; set; }
        public string DataLayerFrameworkNamespace { get; set; }
        public string DataLayerContainerNamespace { get; set; }
        public string FileStorageDataLayerAssemblyName { get; set; }
        public string FileStorageDataLayerNamespace { get; set; }
        public string FileStorageDataLayerFrameworkNamespace { get; set; }
        public string SqliteDataLayerAssemblyName { get; set; }
        public string SqliteDataLayerNamespace { get; set; }
        public string SqliteDataLayerFrameworkNamespace { get; set; }
        public string SqliteDatabasePath { get; set; }
        public string ServiceLayerNamespace { get; set; }
        public string ServiceLayerFrameworkNamespace { get; set; }
        public string ServiceLayerModelNamespace { get; set; }
        public string ServiceLayerSimpleModelNamespace { get; set; }
        public string ServiceLayerControllerNamespace { get; set; }
        public string ServiceName { get; set; }
        public string ServiceApiName { get; set; }
        public string UILayerNamespace { get; set; }
        public string UILayerFrameworkNamespace { get; set; }
        public string UILayerModelNamespace { get; set; }
        public string UILayerViewModelNamespace { get; set; }
        public string WebLayerNamespace { get; set; }
        public string CollectionTypeNameFormat { get; set; }
        public DomainCommandCollection DomainCommands { get; private set; }
        public ConstraintCollection Constraints { get; private set; }
        public bool HasDataLayer { get; set; }
        public bool HasFileStorageDataLayer { get; set; }
        public bool HasSqliteDataLayer { get; set; }
        public bool HasLocalDataPortal { get; set; }
        public bool HasRemoteDataPortal { get; set; }
        public bool HasUILayer { get; set; }
        public bool HasWebLayer { get; set; }
        public bool HasWebApiLayer { get; set; }
        public bool HasCommonMembers { get; set; }
        public bool HasServiceModel { get; set; }
        public bool HasSimpleServiceModel { get; set; }

        #region DatabaseDomainObjects

        private DomainObjectCollection _FilteredDatabaseDomainObjects;
        private DomainObjectCollection _DatabaseDomainObjects;
        public DomainObjectCollection DatabaseDomainObjects
        {
            get
            {
                if (this.DomainModelFilter != null)
                {
                    if (_FilteredDatabaseDomainObjects == null)
                    {
                        _FilteredDatabaseDomainObjects = new DomainObjectCollection();
                        foreach (var item in _DatabaseDomainObjects)
                        {
                            if (this.DomainModelFilter.ExcludedDomainObjects.Contains(item.NameInDataStore))
                                continue;
                            _FilteredDatabaseDomainObjects.Add(item);
                        }
                    }
                    return _FilteredDatabaseDomainObjects;
                }
                return _DatabaseDomainObjects;
            }
            private set
            {
                _DatabaseDomainObjects = value;
                _FilteredDatabaseDomainObjects = null;
                this.DomainObjects = null;
            }
        }

        #endregion
        #region DomainModelFilter

        private DomainModelFilter _DomainModelFilter;
        public DomainModelFilter DomainModelFilter
        {
            get
            {
                return _DomainModelFilter;
            }
            set
            {
                _DomainModelFilter = value;
                ClearCache();
            }
        }

        #endregion
        #region DomainObjects

        private DomainObjectCollection _DomainObjects;
        public DomainObjectCollection DomainObjects
        {
            get
            {
                if (_DomainObjects == null)
                {
                    _DomainObjects = new DomainObjectCollection();
                    foreach (var item in this.DatabaseDomainObjects)
                    {
                        if (!item.IsDatabaseOnly)
                            _DomainObjects.Add(item);
                    }
                }
                return _DomainObjects;
            }
            private set
            {
                _DomainObjects = value;
            }
        }

        #endregion
        #region ModelName

        private string _ModelName = string.Empty;
        public string ModelName
        {
            get
            {
                return _ModelName;
            }
            set
            {
                if (value == null)
                    value = string.Empty;
                _ModelName = value;
            }
        }

        #endregion
        #region DataLayerContainerName

        private string _DataLayerContainerName;
        public string DataLayerContainerName
        {
            get
            {
                return _DataLayerContainerName;
            }
            set
            {
                if (value == null)
                    value = string.Empty;
                if (string.IsNullOrWhiteSpace(this.DomainName))
                    this.DomainName = value.Replace("Entities", "");
                _DataLayerContainerName = value;
            }
        }

        #endregion
        #region HasDataPortal

        public bool HasDataPortal
        {
            get
            {
                if (this.HasLocalDataPortal)
                    return true;
                if (this.HasRemoteDataPortal)
                    return true;
                return false;
            }
        }

        #endregion
        #region WebApiOperationTypes

        public OperationTypes? WebApiOperationTypes
        {
            get
            {
                if (this.DomainObjects == null)
                    return null;
                if (this.DomainObjects.Count == 0)
                    return null;
                return this.DomainObjects[0].WebApiOperationTypes;
            }
            set
            {
                if (value == null)
                    return;
                if (this.DomainObjects == null)
                    return;
                foreach (var domainObject in this.DomainObjects)
                    domainObject.WebApiOperationTypes = value.Value;
            }
        }

        #endregion

        #region AddDatabaseRelation

        public DomainObjectRelation AddDatabaseRelation(string sourceDomainObjectName, string relatedDomainObjectName,
            Multiplicity sourceObjectMultiplicity, Multiplicity relatedObjectMultiplicity)
        {
            return AddDatabaseRelation(sourceDomainObjectName, relatedDomainObjectName, sourceObjectMultiplicity, relatedObjectMultiplicity,
                null, null, null, null, null, null, null, null, null);
        }
        public DomainObjectRelation AddDatabaseRelation(string sourceDomainObjectName, string relatedDomainObjectName,
            Multiplicity sourceObjectMultiplicity, Multiplicity relatedObjectMultiplicity, string name)
        {
            return AddDatabaseRelation(sourceDomainObjectName, relatedDomainObjectName, sourceObjectMultiplicity, relatedObjectMultiplicity, name,
                null, null, null, null, null, null, null, null);
        }
        public DomainObjectRelation AddDatabaseRelation(string sourceDomainObjectName, string relatedDomainObjectName,
            Multiplicity sourceObjectMultiplicity, Multiplicity relatedObjectMultiplicity, string name, string sourceObjectPropertyName1, string relatedObjectPropertyName1)
        {
            return AddDatabaseRelation(sourceDomainObjectName, relatedDomainObjectName, sourceObjectMultiplicity, relatedObjectMultiplicity, name,
                sourceObjectPropertyName1, relatedObjectPropertyName1,
                null, null, null, null, null, null);
        }
        public DomainObjectRelation AddDatabaseRelation(string sourceDomainObjectName, string relatedDomainObjectName,
            Multiplicity sourceObjectMultiplicity, Multiplicity relatedObjectMultiplicity, string name, string sourceObjectPropertyName1, string relatedObjectPropertyName1,
            string sourceObjectPropertyName2, string relatedObjectPropertyName2)
        {
            return AddDatabaseRelation(sourceDomainObjectName, relatedDomainObjectName, sourceObjectMultiplicity, relatedObjectMultiplicity, name,
                sourceObjectPropertyName1, relatedObjectPropertyName1,
                sourceObjectPropertyName2, relatedObjectPropertyName2,
                null, null, null, null);
        }
        public DomainObjectRelation AddDatabaseRelation(string sourceDomainObjectName, string relatedDomainObjectName,
            Multiplicity sourceObjectMultiplicity, Multiplicity relatedObjectMultiplicity, string name, string sourceObjectPropertyName1, string relatedObjectPropertyName1,
            string sourceObjectPropertyName2, string relatedObjectPropertyName2, string sourceObjectPropertyName3, string relatedObjectPropertyName3)
        {
            return AddDatabaseRelation(sourceDomainObjectName, relatedDomainObjectName, sourceObjectMultiplicity, relatedObjectMultiplicity, name,
                sourceObjectPropertyName1, relatedObjectPropertyName1,
                sourceObjectPropertyName2, relatedObjectPropertyName2,
                sourceObjectPropertyName3, relatedObjectPropertyName3,
                null, null);
        }
        public DomainObjectRelation AddDatabaseRelation(string sourceDomainObjectName, string relatedDomainObjectName,
            Multiplicity sourceObjectMultiplicity, Multiplicity relatedObjectMultiplicity, string name, string sourceObjectPropertyName1, string relatedObjectPropertyName1,
            string sourceObjectPropertyName2, string relatedObjectPropertyName2, string sourceObjectPropertyName3, string relatedObjectPropertyName3,
            string sourceObjectPropertyName4, string relatedObjectPropertyName4)
        {
            if (string.IsNullOrWhiteSpace(sourceDomainObjectName))
                return null;
            if (string.IsNullOrWhiteSpace(relatedDomainObjectName))
                return null;
            var sourceObject = GetDomainObject(sourceDomainObjectName);
            if (sourceObject == null)
                return null;
            var relatedObject = GetDomainObject(relatedDomainObjectName);
            if (relatedObject == null)
                return null;
            return sourceObject.AddDatabaseRelation(relatedObject, sourceObjectMultiplicity, relatedObjectMultiplicity, name, sourceObjectPropertyName1, relatedObjectPropertyName1,
                sourceObjectPropertyName2, relatedObjectPropertyName2, sourceObjectPropertyName3, relatedObjectPropertyName3, sourceObjectPropertyName4, relatedObjectPropertyName4);
        }

        #endregion
        #region AddIndex

        public DomainObjectIndex AddIndex(string domainObjectName, string indexName, bool isUnique, string propertyName1)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddIndex(indexName, isUnique, propertyName1);

            return null;
        }

        public DomainObjectIndex AddIndex(string domainObjectName, string indexName, bool isUnique, string propertyName1, string propertyName2)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddIndex(indexName, isUnique, propertyName1, propertyName2);

            return null;
        }

        public DomainObjectIndex AddIndex(string domainObjectName, string indexName, bool isUnique, string propertyName1, string propertyName2, string propertyName3)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddIndex(indexName, isUnique, propertyName1, propertyName2, propertyName3);

            return null;
        }

        public DomainObjectIndex AddIndex(string domainObjectName, string indexName, bool isUnique, string propertyName1, string propertyName2, string propertyName3, string propertyName4)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddIndex(indexName, isUnique, propertyName1, propertyName2, propertyName3, propertyName4);

            return null;
        }

        #endregion
        #region AddProperty

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "string")]
        public DomainObjectProperty AddProperty(string domainObjectName, string propertyName, bool isNullable, string defaultValue, int? maxLength, string stringFormat, string valueFormat, PropertyType type)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddProperty(propertyName, isNullable, defaultValue, maxLength, stringFormat, valueFormat, type);

            return null;
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "string")]
        public DomainObjectProperty AddProperty(string domainObjectName, string propertyName, bool isNullable, string defaultValue, int? maxLength, string stringFormat, string valueFormat, string typeName, bool isValueType)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddProperty(propertyName, isNullable, defaultValue, maxLength, stringFormat, valueFormat, typeName, isValueType);

            return null;
        }

        #endregion
        #region AddStringProperty

        public DomainObjectProperty AddStringProperty(string domainObjectName, string propertyName, string defaultValue, int? maxLength, string valueFormat)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.AddStringProperty(propertyName, defaultValue, maxLength, valueFormat);

            return null;
        }

        #endregion
        #region ClearCache

        public void ClearCache()
        {
            _FilteredDatabaseDomainObjects = null;
            this.DomainObjects = null;
            if (_DatabaseDomainObjects != null)
                _DatabaseDomainObjects.ClearCache();
        }

        #endregion
        #region CompareTypes

        public TypeComparisonResult CompareTypes(DomainObjectProperty propertyA, DomainObjectProperty propertyB, TypeComparison typeComparison)
        {
            if (propertyA == null)
                throw new System.ArgumentNullException("propertyA");
            if (propertyB == null)
                throw new System.ArgumentNullException("propertyB");
            switch (typeComparison)
            {
                case TypeComparison.CompareDomainProperty:
                    return CompareTypes(propertyA.TypeName, propertyB.TypeName, propertyA.NotNullableTypeName, propertyB.NotNullableTypeName);
                case TypeComparison.CompareDataStoreProperty:
                    return CompareTypes(propertyA.TypeNameInDataStore, propertyB.TypeNameInDataStore, propertyA.NotNullableTypeNameInDataStore, propertyB.NotNullableTypeNameInDataStore);
                default:
                    return CompareTypes(propertyA.TypeName, propertyB.TypeNameInDataStore, propertyA.NotNullableTypeName, propertyB.NotNullableTypeNameInDataStore);
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        public TypeComparisonResult CompareTypes(string typeNameA, string typeNameB, string notNullableTypeNameA)
        {
            if (string.IsNullOrWhiteSpace(typeNameA))
            {
                if (string.IsNullOrWhiteSpace(typeNameB))
                    return TypeComparisonResult.Equal;
                return TypeComparisonResult.NotEqual;
            }
            else if (string.IsNullOrWhiteSpace(typeNameB))
                return TypeComparisonResult.NotEqual;
            if (typeNameA.Equals(typeNameB, System.StringComparison.OrdinalIgnoreCase))
                return TypeComparisonResult.Equal;

            if (string.IsNullOrWhiteSpace(notNullableTypeNameA))
                return TypeComparisonResult.NotEqual;
            else
            {
                if (typeNameB.Equals(notNullableTypeNameA, System.StringComparison.OrdinalIgnoreCase))
                    return TypeComparisonResult.NullableAndNotNullable;
                else
                    return TypeComparisonResult.NotEqual;
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        public TypeComparisonResult CompareTypes(string typeNameA, string typeNameB, string notNullableTypeNameA, string notNullableTypeNameB)
        {
            if (string.IsNullOrWhiteSpace(typeNameA))
            {
                if (string.IsNullOrWhiteSpace(typeNameB))
                    return TypeComparisonResult.Equal;
                return TypeComparisonResult.NotEqual;
            }
            else if (string.IsNullOrWhiteSpace(typeNameB))
                return TypeComparisonResult.NotEqual;
            if (typeNameA.Equals(typeNameB, System.StringComparison.OrdinalIgnoreCase))
                return TypeComparisonResult.Equal;

            if (string.IsNullOrWhiteSpace(notNullableTypeNameA))
            {
                if (string.IsNullOrWhiteSpace(notNullableTypeNameB))
                    return TypeComparisonResult.NotEqual;
                else if (typeNameA.Equals(notNullableTypeNameB, System.StringComparison.OrdinalIgnoreCase))
                    return TypeComparisonResult.NotNullableAndNullable;
            }
            else if (string.IsNullOrWhiteSpace(notNullableTypeNameB))
            {
                if (typeNameB.Equals(notNullableTypeNameA, System.StringComparison.OrdinalIgnoreCase))
                    return TypeComparisonResult.NullableAndNotNullable;
                else
                    return TypeComparisonResult.NotEqual;
            }
            else if (notNullableTypeNameA.Equals(notNullableTypeNameB, System.StringComparison.OrdinalIgnoreCase))
            {
                if (typeNameA.Equals(notNullableTypeNameA, System.StringComparison.OrdinalIgnoreCase))
                    return TypeComparisonResult.NotNullableAndNullable;
                else
                    return TypeComparisonResult.NullableAndNotNullable;
            }

            return TypeComparisonResult.NotEqual;
        }

        #endregion
        #region ConvertCaseString

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        public string ConvertCaseString(string value, CaseType caseType)
        {
            return TypeMapper.ConvertCaseString(value, caseType);
        }

        #endregion
        #region CopyPropertyValues

        public void CopyPropertyValues(string sourceDomainObjectName, string sourcePropertyName, string targetDomainObjectName, string targetPropertyName, bool copyMaxLength)
        {
            var source = GetDomainObjectProperty(sourceDomainObjectName, sourcePropertyName);
            if (source == null)
                return;
            var target = GetDomainObjectProperty(targetDomainObjectName, targetPropertyName);
            if (target == null)
                return;
            if (copyMaxLength)
                target.MaxLength = source.MaxLength;
        }

        #endregion
        #region GetDomainObject

        public DomainObject GetDomainObject(string domainObjectName)
        {
            return (from o in this.DomainObjects
                    where o.Name.Equals(domainObjectName, System.StringComparison.OrdinalIgnoreCase)
                    select o).FirstOrDefault();
        }

        #endregion
        #region GetDomainObjectProperty

        public DomainObjectProperty GetDomainObjectProperty(string domainObjectName, string propertyName)
        {
            var item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.GetProperty(propertyName);
            return null;
        }

        #endregion
        #region GetDomainObjectProperties

        public IEnumerable<DomainObjectProperty> GetDomainObjectProperties(string domainObjectName, PropertyType? propertyType, string typeName, bool? isGenerated, bool? isKey, bool? isNullable)
        {
            var properties = new List<DomainObjectProperty>();
            if (!string.IsNullOrWhiteSpace(domainObjectName))
            {
                var item = GetDomainObject(domainObjectName);
                if (item != null)
                {
                    var p = item.GetProperties(propertyType, typeName, isGenerated, isKey, isNullable);
                    if (p != null)
                        properties.AddRange(p);
                }
            }
            else
            {
                foreach (var item in this.DomainObjects)
                {
                    var p = item.GetProperties(propertyType, typeName, isGenerated, isKey, isNullable);
                    if (p != null)
                        properties.AddRange(p);
                }
            }
            return properties;
        }

        #endregion
        #region GetDomainObjectRelations

        public System.Collections.ObjectModel.Collection<DomainObjectRelation> GetDomainObjectRelations(string sourceDomainObjectName, string relatedDomainObjectName)
        {
            var item = GetDomainObject(sourceDomainObjectName);
            if (item != null)
                return item.GetRelations(relatedDomainObjectName);
            return null;
        }

        #endregion
        #region GetModelPath

        public string GetModelPath()
        {
            return GetModelPath("Model");
        }
        public string GetModelPath(string emptyValue)
        {
            return GetModelPath(emptyValue, null);
        }
        public string GetModelPath(string emptyValue, string prefix)
        {
            if (string.IsNullOrWhiteSpace(this.ModelName))
            {
                if (emptyValue != null)
                    return emptyValue;
                else
                    return string.Empty;
            }
            if (prefix == null)
                return this.ModelName + "Model";
            return prefix + this.ModelName + "Model";
        }

        #endregion
        #region GetModelNameResolved

        public string GetModelNameResolved()
        {
            return GetModelNameResolved("Model");
        }
        public string GetModelNameResolved(string emptyValue)
        {
            return GetModelNameResolved(emptyValue, null);
        }
        public string GetModelNameResolved(string emptyValue, string prefix)
        {
            if (string.IsNullOrWhiteSpace(this.ModelName))
            {
                if (emptyValue != null)
                    return emptyValue;
                else
                    return string.Empty;
            }
            if (prefix == null)
                return this.ModelName + "Model";
            return prefix + this.ModelName + "Model";
        }

        #endregion
        #region GetPluralName

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        public string GetPluralName(string name)
        {
            return TypeMapper.GetPluralName(name);
        }

        #endregion
        #region GetValueAsString

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
        public string GetValueAsString(object value)
        {
            return TypeMapper.GetValueAsString(value);
        }

        #endregion
        #region RemoveDomainObjects

        public void RemoveDomainObjects(bool isDatabaseOnly, params string[] names)
        {
            if (names == null)
                return;
            if (this.DatabaseDomainObjects != null)
            {
                this.DatabaseDomainObjects.RemoveItems(isDatabaseOnly, names);
                this.DatabaseDomainObjects.RemoveRelationsByDomainObjectNames(isDatabaseOnly, names);
            }
        }

        #endregion
        #region RemoveAllDomainObjects

        public void RemoveAllDomainObjects(bool isDatabaseOnly, params string[] excludedNames)
        {
            if (this.DatabaseDomainObjects != null)
            {
                var names = this.DatabaseDomainObjects.RemoveAllItems(isDatabaseOnly, excludedNames);
                this.DatabaseDomainObjects.RemoveRelationsByDomainObjectNames(isDatabaseOnly, names);
            }
        }

        #endregion
        #region InitializeDomainObjectsLayers

        public void InitializeDomainObjectsLayers(bool? hasSqliteDataLayer, bool? hasUILayer, bool? hasWebLayer, bool? hasWebApiLayer, params string[] names)
        {
            if (names == null)
                return;
            if (this.DatabaseDomainObjects != null)
                this.DatabaseDomainObjects.InitializeItemsLayers(hasSqliteDataLayer, hasUILayer, hasWebLayer, hasWebApiLayer, names);
        }

        #endregion
        #region InitializeAllDomainObjectsLayers

        public void InitializeAllDomainObjectsLayers(bool? hasSqliteDataLayer, bool? hasUILayer, bool? hasWebLayer, bool? hasWebApiLayer, params string[] excludedNames)
        {
            if (this.DatabaseDomainObjects != null)
                this.DatabaseDomainObjects.InitializeAllItemsLayers(hasSqliteDataLayer, hasUILayer, hasWebLayer, hasWebApiLayer, excludedNames);
        }

        #endregion
        #region SetPropertyAsCultureItem

        public DomainObjectProperty SetPropertyAsCultureItem(string domainObjectName, string propertyName)
        {
            var item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.SetPropertyAsCultureItem(propertyName);
            return null;
        }

        #endregion
        #region SetPropertyAsCustomType

        public DomainObjectProperty SetPropertyAsCustomType(string domainObjectName, string propertyName, string typeName, string defaultValue, bool? isNullable,
            string deserializeFormat, string stringFormat, string valueFormat, string valueFormatInDataStore)
        {
            var item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.SetPropertyAsCustomType(propertyName, typeName, defaultValue, isNullable, deserializeFormat, stringFormat, valueFormat, valueFormatInDataStore);
            return null;
        }

        #endregion
        #region SetPropertyAsEnum

        public DomainObjectProperty SetPropertyAsEnum(string domainObjectName, string propertyName, string enumName, string defaultValue, bool? isNullable)
        {
            var item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.SetPropertyAsEnum(propertyName, enumName, defaultValue, isNullable);
            return null;
        }

        #endregion
        #region SetPropertyName

        public DomainObjectProperty SetPropertyName(string domainObjectName, string propertyName, string newPropertyName)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.SetPropertyName(propertyName, newPropertyName);
            return null;
        }

        #endregion
        #region SetPropertyValues

        public DomainObjectProperty SetPropertyValues(string domainObjectName, string propertyName, string defaultValue)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.SetPropertyValues(propertyName, defaultValue);
            return null;
        }
        public DomainObjectProperty SetPropertyValues(string domainObjectName, string propertyName, string defaultValue, int? maxLength, decimal? minValue, decimal? maxValue, byte? maxDecimalCount)
        {
            DomainObject item;

            item = GetDomainObject(domainObjectName);
            if (item != null)
                return item.SetPropertyValues(propertyName, defaultValue, maxLength, minValue, maxValue, maxDecimalCount);
            return null;
        }

        #endregion

        #endregion
        #region Constructors

        public DomainModel()
        {
            this.CollectionTypeNameFormat = "{0}Collection";
            this.DatabaseDomainObjects = new DomainObjectCollection();
            this.DatabaseDomainObjects.SetDomainModel(this);
            this.DomainCommands = new DomainCommandCollection();
            this.DomainCommands.SetDomainModel(this);
            this.Constraints = new ConstraintCollection();
            this.HasDataLayer = true;
            this.HasFileStorageDataLayer = false;
            this.HasSqliteDataLayer = false;
            this.HasLocalDataPortal = true;
            this.HasRemoteDataPortal = false;
            this.HasUILayer = true;
            this.HasWebLayer = false;
            this.HasWebApiLayer = false;
            this.HasCommonMembers = true;
        }

        #endregion
    }
}
